package edu.ptu.springboot04.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @BelongsProject: springboot04
 * @BelongsPackage: edu.ptu.springboot04.config
 * @Author: HYJ
 * @CreateTime: 2025-03-21  22:00
 * @Description: Mybatis配置类
 * @Version: 1.0
 */
@EnableTransactionManagement
public class MPConfig {

    @Bean
    // 创建MybatisPlusInterceptor对象
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        // 添加乐观锁插件

        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        // 添加分页插件

        return interceptor;
    }

}
